package com.file;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class Test_6 {
    public static void main(String[] args) {
        read();
    }

//按字符读取
    public static void read(){
        String pathname="D:\\javacode\\javacode\\J2024_11_16\\hello.txt";
        FileReader fileReader=null;
        char[] buf=new char[16];
        int readlen=0;
        try {
            fileReader=new FileReader(pathname);
            while((readlen=fileReader.read(buf))!=-1){
             //   System.out.print((char)readlen);
                System.out.println(new String(buf,0,readlen));
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            if(fileReader!=null){
                try {
                    fileReader.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
}
